Bail out from watching earlier using watchOptions.ignored #58
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The Problem:
In our case, we use monorepo with all of the dependencies in the root
node_modules
folder which are then symlinked to individual packages, we experience significant performance degradation, because watcher is going very deep through circular symlinks which slows down initial build time, and makes consequent re-builds extremely slow, and the CPU consumption is enormous.What we've tried:
AFAIK Webpack has 2 ways of ignoring files from watch:
watchOptions.ignored
– they are passed down to chokidar. This one either not working properly in chokidar or I don't understand how it is supposed to work, because whatever I pass through this option isn't helping at all.WatchIgnorePlugin
– that extendsNodeWatchFileSystem
. And can filter initial set of files, but DirectoryWatcher usingsetNestedWatching
which adds nested directories to watch and that skipsWatchIgnorePlugin
.Temporary solution
We came up with a temporary solution that works for us right now, but it is very hacky. We are monkey patching
DirectoryWatcher
so it ignoresnode_modules
:That helped a lot, re-builds now are almost instant, comparing to 30s - 60s before this fix. Though, we are not exactly happy about this solution :)
Proposed solution
What I'm proposing in this PR is that we can use
watchOptions.ignored
to bail out from watching early. Thus breaking out of the circular symlinks hell. Also it speeds up everything a bit, sincewatchpack
doesn't have to care about ignored folders/files.Maybe you can suggest better approach for doing this. Or better places where I can add this check.
Also I haven't added any tests yet, since I didn't want to spend time writing them being not sure whether proposed approach is ok for you or not. But if it's fine with you, I'll add tests.
I looked at this PR #41 which potentially can solve this issue, but since it has probably died almost a year ago I think considering other options make total sense.